package com.explorati.LeetCode091.numDecodings;

/**
 * @ Author : Weijian_Wang
 * @ Date : Created in 21:36 2020/10/21 0021
 * @ Description ：
 */
public class Solution {

    public int numDecodings(String s) {
        if(s.length() == 0 || s == null) {
            return 0;
        }
        return decodingNum(s, 0);
    }

    private int decodingNum(String s, int start) {
       if(start == s.length()) {
           return 1;
       }

        //如果以0开头，则返回
        if(s.charAt(start) == '0') {
            return 0;
        }

        int ans1 = decodingNum(s, start + 1);
        int ans2 = 0;
        if(s.length() - 1 > start) {
            int range = (s.charAt(start) - '0') * 10 + (s.charAt(start + 1) - '0');
            if(range >= 10 && range <= 26) {
                ans2 = decodingNum(s, start + 2);
            }
        }

        return ans1 + ans2;
    }
}
